home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue54 / Clinic / Grid16U.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-12-28  |  1.1 KB  |  49 lines

  1. unit Grid16U;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Grids, DBGrids, DB, DBTables;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Table1: TTable;
  12.     DataSource1: TDataSource;
  13.     DBGrid1: TDBGrid;
  14.     procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  15.       Field: TField; State: TGridDrawState);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  30.   Field: TField; State: TGridDrawState);
  31. begin
  32.   with (Sender as TDBGrid) do
  33.   begin
  34.     { Our criteria means green cells, but if the cell is selected, }
  35.     { stick with the default blue background but use green font }
  36.     if Field.DataSet.FieldByName('TaxRate').AsFloat > 0 then
  37.       if gdSelected in State then
  38.         Canvas.Font.Color := clGreen
  39.       else
  40.       begin
  41.         Canvas.Brush.Color := clGreen;
  42.         Canvas.Font.Color := clWhite;
  43.       end;
  44.     DefaultDrawDataCell(Rect, Field, State)
  45.   end
  46. end;
  47.  
  48. end.
  49.